package com.zzyl.nursing.task;

import com.zzyl.nursing.domain.Contract;
import com.zzyl.nursing.mapper.ContractMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class Time {

    @Autowired
    private ContractMapper contractMapper;

    @Scheduled(cron = "0 0 4 * * ?")
    public void checkstatus(){
        //获取所有合同
        List<Contract> list = contractMapper.findAll();
        for (Contract contract :list){
            if (LocalDateTime.now().isBefore(contract.getEndDate())&&LocalDateTime.now().isAfter(contract.getStartDate())){
                contract.setStatus(1L);
                contractMapper.updateById(contract);
            }else {
                contract.setStatus(0L);
                contractMapper.updateById(contract);
            }
        }

    };
}
